package com.example.finalthesis.the_db4o_project;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.widget.SlidingPaneLayout;
import android.view.View;

import com.example.finalthesis.the_db4o_project.ListOFObjects.ItemListener;
//l
public class MainActivity extends Activity implements ItemListener{
    SlidingPaneLayout pane;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pane = (SlidingPaneLayout) findViewById(R.id.sp);
        pane.setPanelSlideListener(new PaneListener());

        if (!pane.isSlideable()) {
            getFragmentManager().findFragmentById(R.id.leftpane).setHasOptionsMenu(false);
            getFragmentManager().findFragmentById(R.id.rightpane).setHasOptionsMenu(true);
        }
    }


//den isxyoun ta menu
    private class PaneListener implements SlidingPaneLayout.PanelSlideListener {

        @Override
        public void onPanelClosed(View view) {
            System.out.println("Panel closed");

            getFragmentManager().findFragmentById(R.id.leftpane).setHasOptionsMenu(false);
            getFragmentManager().findFragmentById(R.id.rightpane).setHasOptionsMenu(true);
        }

        @Override
        public void onPanelOpened(View view) {
            System.out.println("Panel opened");
            getFragmentManager().findFragmentById(R.id.leftpane).setHasOptionsMenu(true);
            getFragmentManager().findFragmentById(R.id.rightpane).setHasOptionsMenu(false);
        }

        @Override
        public void onPanelSlide(View view, float arg1) {
            System.out.println("Panel sliding");
        }

    }



    @Override
    public void onChangeItemOfObject(String item) {
        // We get notified when user clicks on a bookmark in the ListBookmarkFragment
       // System.out.println("Bookmark ["+item+"]");
        TheMainView f = (TheMainView)getFragmentManager().findFragmentById(R.id.rightpane);
        f.setObjectItem(item);

    }
}
